package com.xb.cloud.gateway.client;

import com.alibaba.fastjson.JSON;

/**
 * 返回给客户端的信息,主要包括错误编号,错误分类,错误详情,业务返回结果信息(错误编码为0,表示没有错误,正常返回)
 * 
 * @Author wangxiaowu
 * @CreateTime 2014-7-18 下午01:47:30
 */

// TODO: 1. "fail to build context" 定义 static final 2. 公用getter setter方法名不要“—”
// 3.统一未登录错误编码 4.增加一个静态 未登录的构建方法

public final class RtnInfo {

	/**
	 * 状态编号
	 */
	private String rtnCode;
	/**
	 * 状态描述
	 */
	private String rtnMsg;
	/**
	 * 错误信息描述
	 */
	private String rtnExt;

	/**
	 * pd提供的错误提示信息
	 */
	private String rtnTip;

	/**
	 * 服务器端控制app强制提示
	 */
	private String rtnFtype;

	/**
	 * 适配器响应的业务对象
	 */
	private Object data;

	public RtnInfo() {

	}

	/**
	 * 构造器1
	 * 
	 * @return
	 */
	public RtnInfo(String rtnCode, String rtnMsg, String rtnExt) {
		this(rtnCode, rtnMsg, rtnExt, null);
	}

	public RtnInfo(String rtnCode, String rtnMsg, String rtnExt, Object data) {
		super();
		this.rtnCode = rtnCode;
		this.rtnMsg = rtnMsg;
		this.rtnExt = rtnExt;
		this.rtnTip = "";
		this.rtnFtype = "0";
		this.data = data;
	}

	public static RtnInfo ParameterErrRtnInfo(String errMessage) {
		return new RtnInfo(RtnCodes.PARAMETER_ERROR, errMessage, "", null);
	}

	public static RtnInfo RightWlRtnInfo(Object data) {
		return new RtnInfo(RtnCodes.SUCCESS, "", "", data);
	}

	public static RtnInfo TokenErrWlRtnInfo() {
		return new RtnInfo(RtnCodes.USER_TOKEN_ERROR, "", "", null);
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getRtnCode() {
		return rtnCode;
	}

	public void setRtnCode(String rtnCode) {
		this.rtnCode = rtnCode;
	}

	public String getRtnMsg() {
		return rtnMsg;
	}

	public void setRtnMsg(String rtnMsg) {
		this.rtnMsg = rtnMsg;
	}

	public String getRtnExt() {
		return rtnExt;
	}

	public void setRtnExt(String rtnExt) {
		this.rtnExt = rtnExt;
	}

	public String getRtnTip() {
		return rtnTip;
	}

	public void setRtnTip(String rtnTip) {
		this.rtnTip = rtnTip;
	}

	public String getRtnFtype() {
		return rtnFtype;
	}

	public void setRtnFtype(String rtnFtype) {
		this.rtnFtype = rtnFtype;
	}

	@Override
	public String toString() {
		return "RtnInfo [rtnCode=" + rtnCode + ", rtnMsg=" + rtnMsg + ", rtnExt=" + rtnExt + ", rtnTip=" + rtnTip
				+ ", rtnFtype=" + rtnFtype + ", data=" + JSON.toJSONString(data) + "]";
	}

}
